# GF_PY3_CLASS/Python_3_List_Split.py
# Create by GF 2025-09-20 00:53

class Python_3_List_Split(object):

    # Examples:
    # >>> Menbers = [1, 2, 3, 4, 5, 6]
    # >>> Chunk_Menbers_Split_into_Multiple_Chunk(Chunk_Menbers = Menbers, Chunk_Num = 2)
    # [[1, 2, 3], [4, 5, 6]]
    # >>> Menbers = [1, 2, 3, 4, 5, 6, 7]
    # >>> Chunk_Menbers_Split_into_Multiple_Chunk(Chunk_Menbers = Menbers, Chunk_Num = 2)
    # [[1, 2, 3, 7], [4, 5, 6]]

    def into_Multiple_Chunk_and_Save_to_Python_3_List(Chunk_Menbers:list, Chunk_Num:int = 1) -> list:
    
        # Examples:
        # >>> Menbers = [1, 2, 3, 4, 5, 6]
        # >>> Chunk_Menbers_Split_into_Multiple_Chunk(Chunk_Menbers = Menbers, Chunk_Num = 2)
        # [[1, 2, 3], [4, 5, 6]]
        # >>> Menbers = [1, 2, 3, 4, 5, 6, 7]
        # >>> Chunk_Menbers_Split_into_Multiple_Chunk(Chunk_Menbers = Menbers, Chunk_Num = 2)
        # [[1, 2, 3, 7], [4, 5, 6]]
    
        Total_Len = len(Chunk_Menbers)
        # ..............................................
        Mod = Total_Len % Chunk_Num
        Chunk_Len = (Total_Len - Mod) / Chunk_Num
        # ..............................................
        Final = []
        # ..............................................
        Total = 0  # 总数
        Phase = 0  # 阶段总数 (每处理完 1 个 Chunk 的数量为 1 个阶段)
        Ferry = []
        for Element in Chunk_Menbers:
            Total = Total + 1  # 先计数, 后处理 (计入总数)
            Phase = Phase + 1  # 先计数, 后处理 (计入阶段总数)
            Ferry.append(Element)
            if (Phase == Chunk_Len):
                Phase = 0
                Final.append(Ferry.copy())  # 必须拷贝 (Copy) 而不是引用 (Quote)
                Ferry.clear()
            if (Total == Chunk_Len * Chunk_Num):
                break
        # ..............................................
        if (Mod != 0):
            a = Total  # Python 3 List 下标取值从 0 开始, 不需要 Total + 1 取剩余元素
            b = Total + Mod
            for i in range(a, b, 1):
                # Python 3 Range 生成的区间含头不含尾, 例如: range(1, 5, 1) ---> [1, 2, 3, 4]
                Final[i - Total].append(Chunk_Menbers[i])
        # ..............................................
        return Final

# Signed by GF.
